package org.hackystat.timeline.resource.timelineproperties;

import static org.junit.Assert.assertEquals;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.hackystat.timeline.resource.timelineproperties.jaxb.Properties;
import org.hackystat.timeline.resource.timelineproperties.jaxb.Properties.AnalysisType;

import org.junit.Test;

/**
 * The class for testing marshalling and unmarshalling.
 * 
 * @author Alexey R. Olkov
 * 
 */
public class TestTimelinePropertiesResource {

  /**
   * Tests unmarshalling.
   * 
   */
  @Test
  public void testUnmarhaling() {
    try {
      JAXBContext context = JAXBContext
          .newInstance("org.hackystat.timeline.resource.timelineproperties.jaxb");
      Unmarshaller unmarshaller = context.createUnmarshaller();
      File propFile = new File("xml\\project1\\user1\\properties.xml");
      Properties properties = (Properties) unmarshaller.unmarshal(propFile);
      for (AnalysisType type : properties.getAnalysisType()) {
        assertEquals("visible property", type.getProperty().get(0).getKey(), "visible");
        assertEquals("color property", type.getProperty().get(1).getKey(), "color");
      }
    }
    catch (JAXBException e) {
      e.printStackTrace();
    }

  }

}
